package com.qingzhou.web.service.impl.convert;


import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.fastjson2.JSON;
import com.mybatisflex.core.query.QueryWrapper;
import com.qingzhou.system.domain.SysDictData;
import com.qingzhou.system.domain.SysPost;
import com.qingzhou.system.service.ISysDictDataService;
import com.qingzhou.system.service.ISysPostService;
import com.qingzhou.web.repository.entity.FamilyHistoryDetail;
import com.qingzhou.web.service.impl.params.vo.LifeEvaluationOutVo;
import com.qingzhou.web.service.impl.params.vo.LifeEvaluationVo;
import org.noear.solon.Solon;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class LifeEvaluationConverter implements Converter<String> {
    @Override
    public WriteCellData<?> convertToExcelData(String value, ExcelContentProperty contentProperty,
                                               GlobalConfiguration globalConfiguration) {
        WriteCellData<Object> emptyData = new WriteCellData<>("");
        emptyData.setType(CellDataTypeEnum.STRING);
        if(StrUtil.isEmpty(value)) {
            return emptyData;
        }

        LifeEvaluationOutVo outVo = JSON.parseObject(value, LifeEvaluationOutVo.class);
        String outTpl = "编号：{}，出生日期：{}，评分日期：{}";
        List<String> collect = new ArrayList<>();
        collect.add(StrUtil.format(outTpl,outVo.getNumber(),outVo.getBirthDate(),outVo.getBirthDate()));
        String tpl = "评分项：{}，评分：{}，评分描述：{}";
        List<LifeEvaluationVo> answers = outVo.getAnswers();
        collect.addAll(answers.stream().map(item -> StrUtil.format(tpl, item.getLabel(), item.getScore(), item.getScoreDesc())).collect(Collectors.toList()));

        return new WriteCellData<>(CollUtil.join(collect,"\n"));
    }
}
